package com.genymobile.scrcpy.five.config;

import android.util.Log;

import java.util.HashMap;
import java.util.Map;

/**
 * 解析命令行传入的 displayId 和 输入node的映射关系
 * eg: /dev/input/event0=0,/dev/input/event2=4
 */
public class EventMapFromArgs implements IEventMap {

    private static final String TAG = EventMapFromArgs.class.getSimpleName();

    public static IEventMap parse(String str) {
        Log.d(TAG, "parse() " + str);
        EventMapFromArgs ret = new EventMapFromArgs();
        String[] arr = str.split(",");
        for (String one : arr) {
            one = one.trim();
            String[] tmp = one.split("=");
            if (tmp.length == 2) {
                try {
                    int displayId  =  Integer.parseInt(tmp[1].trim());
                    ret.mMap.put(tmp[0].trim(), displayId);
                } catch (Exception ignored) {}
            }
        }
        return ret;
    }

    private final Map<String, Integer> mMap = new HashMap<>();

    @Override
    public Map<String, Integer> getDisplay2EventNodeMap() {
        return mMap;
    }
}
